#ifndef SUDOKUCANDIDATES_H_
#define SUDOKUCANDIDATES_H_

#include <QBitArray>
#include <QList>
#include <QVector>

#include "SudokuMethodType.h"

class SudokuCandidates
{

public:
    SudokuCandidates();
    SudokuCandidates(int size, bool value = false);
    SudokuCandidates(const SudokuCandidates &other);
    SudokuCandidates& operator=(const SudokuCandidates &other);
    ~SudokuCandidates();

    inline int count(bool on) const { return mCandidates.count(on); }
    inline int size() const { return mCandidates.size(); }
    inline bool at(int i) const { return mCandidates.at(i); }
    inline bool setAllPossible()
    {
        // TODO Empty or maybe diffetent default value?
        // Set all eliminate type to Empty
        mEliminateTypeVector.fill(Empty);
        // Set all candidates to possible
        return mCandidates.fill(true);
    }

    /**
      * Sets all Eliminated candidates to possible
      */
    void resetEliminated();

    inline void setCandidate(int i, bool value, CellFillerTypes method)
    {
        Q_ASSERT(i<mEliminateTypeVector.size());
        Q_ASSERT(i<mCandidates.count());
        Q_ASSERT(Empty == mEliminateTypeVector[i]);
        Q_ASSERT(value != mCandidates.at(i));

        mEliminateTypeVector[i] = method;
        mCandidates.setBit(i, value);
    }

    inline CellFillerTypes getMethod(int index) const
    {
        Q_ASSERT(index < mEliminateTypeVector.size());
        return mEliminateTypeVector[index];
    }

    inline int getEliminateCount(CellFillerTypes method) const
    {
        return mEliminateTypeVector.count(method);
    }

    /**
      * Assumes that there is at least one ,,true'' value in array
      * Call QBitArray::count(true) to check before calling
      */
    int getFirstPossibleIndex() const;
    /**
      * @return List of candidates (starting from 0)
      */
    QList<int> getCandidateList() const;

private:
    /**
      * List of candidates
      */
    QBitArray mCandidates;
    /**
      * List of methods that elimindated candidate from each cell
      */
    QVector<CellFillerTypes> mEliminateTypeVector;
};

#endif /*SUDOKUCANDIDATES_H_*/
